<template>
  <div v-if="list.length > 0">
    <div v-for="(item, key) in list" :key="key">
      <div class="item">
        <label
          ><input type="checkbox" v-model="item.complete" />
          {{ item.title }}
        </label>
        <button @click="del(key)">删除</button>
      </div>
    </div>
  </div>
  <div v-else>暂无任务</div>
</template>
<script>
import { defineComponent } from "vue";
export default defineComponent({
  name: "navMain",
  props: {
    list: {
      type: Array,
      required: true, //必传
    },
  },
  components: {},
  emits: ["del"],
  setup(props, ctx) {
    // 删除任务
    let del = (key) => {
      ctx.emit("del", key);
    };
    return {
      del,
    };
  },
});
</script>
<style lang="scss" scoped>
.item {
  height: 35px;
  line-height: 35px;
  width: 200px;
  display: flex;
  justify-content: space-between;
  align-items: center;

  label {
    cursor: pointer;
  }
  button {
    height: 25px;
    display: none;
  }
  &:hover {
    background: #efefef;
    button {
      cursor: pointer;
      display: block;
    }
  }
}
</style>
